using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The ClassRoomTableManager class is responsible for managing BO.ClassRoomTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class ClassRoomTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all ClassRoomTable objects in the database.
        /// </summary>
        /// <returns>A list with all ClassRoomTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static ClassRoomTableList GetList(int SchoolKey, int LocationKey)
        {
            return ClassRoomTableDB.GetList(SchoolKey, LocationKey);
        }

        /// <summary>
        /// Gets a single ClassRoomTable from the database without its data.
        /// </summary>
        /// <param name="classRoomKey">The ClassRoomKey of the ClassRoomTable in the database.</param>
        /// <returns>A ClassRoomTable object when the ClassRoomKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static ClassRoomTable GetItem(int classRoomKey)
        {
            return GetItem(classRoomKey, false);
        }

        /// <summary>
        /// Gets a single ClassRoomTable from the database.
        /// </summary>
        /// <param name="classRoomKey">The ClassRoomKey of the ClassRoomTable in the database.</param>
        /// <param name="getClassRoomTableRecords">Determines whether to load all associated ClassRoomTable records as well.</param>
        /// <returns>
        /// A ClassRoomTable object when the ClassRoomKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static ClassRoomTable GetItem(int classRoomKey, bool getClassRoomTableRecords)
        {
            ClassRoomTable myClassRoomTable = ClassRoomTableDB.GetItem(classRoomKey);
            if (myClassRoomTable != null && getClassRoomTableRecords)
            {
                myClassRoomTable.classRoomLocationTables = ClassRoomLocationTableDB.GetListByClassRoomKey(classRoomKey);
            }
            return myClassRoomTable;
        }

        /// <summary>
        /// Saves a ClassRoomTable in the database.
        /// </summary>
        /// <param name="myClassRoomTable">The ClassRoomTable instance to save.</param>
        /// <returns>The new ClassRoomKey if the ClassRoomTable is new in the database or the existing ClassRoomKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(ClassRoomTable myClassRoomTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int classRoomTableClassRoomKey = ClassRoomTableDB.Save(myClassRoomTable);
                //foreach (ClassRoomLocationTable myClassRoomLocationTable in myClassRoomTable.classRoomLocationTables)
                //{
                //    myClassRoomLocationTable.ClassRoomKey = classRoomTableClassRoomKey;
                //    ClassRoomLocationTableDB.Save(myClassRoomLocationTable);
                //}

                //  Assign the ClassRoomTable its new (or existing ClassRoomKey).
                myClassRoomTable.ClassRoomKey = classRoomTableClassRoomKey;

                myTransactionScope.Complete();

                return classRoomTableClassRoomKey;
            }
        }

        /// <summary>
        /// Deletes a ClassRoomTable from the database.
        /// </summary>
        /// <param name="myClassRoomTable">The ClassRoomTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(ClassRoomTable myClassRoomTable)
        {
            return ClassRoomTableDB.Delete(myClassRoomTable.ClassRoomKey);
        }

        /// <summary>
        /// Deletes a ClassRoomTable from the database.
        /// </summary>
        /// <param name="myClassRoomTable">The ClassRoomTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public static bool Delete(int ClassRoomKey)
        {
            return ClassRoomTableDB.Delete(ClassRoomKey);
        }

        #endregion

    }

}
